package u.can.i.up;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import u.can.i.up.db.postgresql.SummationDAO;

public class ReportGenerator {

	static Logger logger = LogManager.getLogger();

	public static void main(String argv[]) {

		int mTotalAppCount = -1;
		int mTotalComponent = -1;
		int mExportedDistinctComponentCount = -1;

		Reader reader = null;
		try {
			reader = Resources.getResourceAsReader("Configuration.xml");
			SqlSessionFactoryBuilder ssfBuilder = new SqlSessionFactoryBuilder();
			SqlSessionFactory sqlSessionFactory = ssfBuilder.build(reader);
			SqlSession sqlSession = sqlSessionFactory.openSession();
			SummationDAO summationDAO = sqlSession.getMapper(SummationDAO.class);
			mTotalAppCount = summationDAO.getAppCount();
			mTotalComponent = summationDAO.getDistinctComponentCount();
			mExportedDistinctComponentCount = summationDAO.getExportedDistinctComponentCount();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				reader.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		logger.info("共有" + mTotalAppCount + "个应用样本，共有" + mTotalComponent + "个组件，其中" + mExportedDistinctComponentCount
				+ "个组件可以导出。");
	}
}
